﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Domain.ExhibitionKpi;

namespace S4Store.Service
{
    public class ExhibitionReportService : BaseService
    {
        public ExhibitionReport GetExhibitionReport(int year, int month, int storeid)
        {
            ExhibitionKpiService ExhibitionKpiService = new Service.ExhibitionKpiService();
            this.GetTranstion().Inject(ExhibitionKpiService);


            ExhibitionReport model = new ExhibitionReport();
            DateTime dt = new DateTime(year, month, 1).MonthLastOrNow();
            model.Year = dt.Year;
            model.Month = dt.Month;
            model.Day = dt.Day;

            model.ExhibitionKpiStandard = ExhibitionKpiService.GetExhibitionKpiStandard(year, month, storeid);
            model.ExhibitionMonthConfig = ExhibitionKpiService.GetExhibitionMonthConfig(year, month, storeid, true);
            model.ExhibitionWeekDatas = ExhibitionKpiService.GetExhibitionWeekDatas(year, month, storeid, true).ToList();
           

            return model;
        }

        public TotalExhibitionReport GetTotalExhibitionReport(int year, int month, int storeid)
        {
            ExhibitionKpiService ExhibitionKpiService = new Service.ExhibitionKpiService();
            this.GetTranstion().Inject(ExhibitionKpiService);


            TotalExhibitionReport model = new TotalExhibitionReport();
            DateTime dt = new DateTime(year, month, 1).MonthLastOrNow();
            model.Year = dt.Year;
            model.Month = dt.Month;
            model.Day = dt.Day;

            model.ExhibitionKpiStandard = ExhibitionKpiService.GetExhibitionKpiStandard(year, month, storeid);
            model.ExhibitionMonthConfig = ExhibitionKpiService.GetExhibitionMonthConfig(year, month, storeid, true);
            model.ExhibitionWeekDatas = ExhibitionKpiService.GetExhibitionWeekDatas(year, month, storeid, true).ToList();


            return model;
        }

        public ExhibitionYearReport GetExhibitionYearReport(int year, int storeid)
        {
            ExhibitionKpiService ExhibitionKpiService = new Service.ExhibitionKpiService();
            this.GetTranstion().Inject(ExhibitionKpiService);

            ExhibitionYearReport model = new ExhibitionYearReport();
            model.Year = year;
            var query = ExhibitionKpiService.GetExhibitionMonthConfigQuery().Where(t => t.Month.Year == year && t.StoreId == storeid&& t.IsConfirmed);
            var months = query.ToList();
            foreach (var m in months)
            {
                var ExhibitionReport = GetExhibitionReport(year, m.Month.Month, storeid);
                model.MonthReports.Add(ExhibitionReport);
            }
            return model;
        }

    }
}
